<template>
  <div class="app-container">
    <el-form label-position="left" :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch">
      <el-form-item label="姓名" prop="name">
        <el-input
          style="width: 130px"
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业班级" prop="areaCollegeGradeProClass">
        <el-cascader
          v-model="queryParams.areaCollegeGradeProClass"
          :options="stuClassCasList"
          :props="stuClassLazyLoadProps"
          placeholder="校区/学院/年级/专业班级"></el-cascader>
      </el-form-item>
      <el-form-item label="房间号" prop="areaBuildingFloorRoom">
        <el-cascader
          v-model="queryParams.areaBuildingFloorRoom"
          :options="areaBuildingFloorRoomList"
          :props="lazyLoadProps"
          placeholder="楼栋/楼层/房间号"></el-cascader>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="queryParams.status">
          <el-option
            v-for="dict in dict.type.stu_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-if="!stuClassInfoFormDisabled"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          v-hasPermi="['stuManage:stu:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          v-hasPermi="['stuManage:stu:remove']"
          @click="handleDelete"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['stuManage:stu:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['stuManage:stu:import']"
        >导入
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="importLeaveData"
          v-hasPermi="['stuManage:stu:import']"
        >导入离校数据
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="stuList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center"/>
      <el-table-column label="学号" align="center" prop="stuNo" width="130"/>
      <el-table-column label="姓名" align="center" prop="name" width="90"/>
      <el-table-column label="学院" align="center" prop="collegeName" :show-overflow-tooltip="true"/>
      <el-table-column label="年级" align="center" prop="gradeName" width="60"/>
      <el-table-column label="专业班级" align="center" prop="proClassName"/>
      <el-table-column label="性别" align="center" width="50">
        <template slot-scope="scope">
          <span v-if="scope.row.sex===0">男</span>
          <span v-if="scope.row.sex===1">女</span>
        </template>
      </el-table-column>
      <el-table-column label="类别" align="center" width="65">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stu_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="身份证号" align="center" prop="idNum"/>
      <el-table-column label="校区" align="center" width="65">
        <template slot-scope="scope">
          <span v-if="scope.row.schoolArea===1">新校区</span>
          <span v-if="scope.row.schoolArea===2">老校区</span>
        </template>
      </el-table-column>
      <el-table-column label="住宿信息" align="center" width="90">
        <template slot-scope="scope">
          <span>{{scope.row.buildingName}}-{{scope.row.roomName}}-{{scope.row.bedName}}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="phone" width="108"/>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.stu_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="现居地址" align="center" prop="addrNow" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" width="80" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini" e
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['stuManage:stu:edit']"
          >
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['stuManage:stu:remove']"
          >
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改学生基本信息对话框   -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" :fullscreen="true" append-to-body>
      <el-row :gutter="12">
        <el-col :span="10">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>基本信息</span>
            </div>
            <div class="text item">
              <el-form ref="form" :disabled="stuBaseInfoFormDisabled" :model="form" :rules="rules" label-width="70px"
                       size="medium">
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="学号" prop="stuNo">
                      <el-input v-model="form.stuNo" placeholder="请输入学号"/>
                    </el-form-item>

                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="姓名" prop="name">
                      <el-input v-model="form.name" placeholder="请输入姓名"/>
                    </el-form-item>

                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="学历" prop="type">
                      <el-select v-model="form.type" placeholder="请选择学历">
                        <el-option
                          v-for="dict in dict.type.stu_type"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="状态" prop="status">
                      <el-select v-model="form.status" placeholder="请选择状态">
                        <el-option
                          v-for="dict in dict.type.stu_status"
                          :key="dict.value"
                          :label="dict.label"
                          :value="dict.value"
                        />
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="手机号" prop="phone">
                      <el-input v-model="form.phone" placeholder="请输入手机号"/>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="身份证号" prop="idNum">
                      <el-input v-model="form.idNum" placeholder="请输入身份证号"/>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="6">
                    <el-form-item label="性别" prop="sex">
                      <el-switch
                        v-model="form.sex"
                        :active-value="0"
                        active-text="男"
                        :inactive-value="1"
                        inactive-text="女">
                      </el-switch>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="党员" prop="isMember">
                      <el-switch
                        v-model="form.isMember"
                        :active-value="1"
                        active-text="是"
                        :inactive-value="0"
                        inactive-text="否">
                      </el-switch>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="团员" prop="isPartyMember">
                      <el-switch
                        v-model="form.isPartyMember"
                        :active-value="1"
                        active-text="是"
                        :inactive-value="0"
                        inactive-text="否">
                      </el-switch>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="寝室长" prop="isAdminDor">
                      <el-switch
                        v-model="form.isAdminDor"
                        :active-value="1"
                        active-text="是"
                        :inactive-value="0"
                        inactive-text="否">
                      </el-switch>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-form-item label="现居地址" prop="addrNow">
                  <el-input v-model="form.addrNow" placeholder="请输入现居地址"/>
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                  <el-input v-model="form.remark" placeholder="请输入备注"/>
                </el-form-item>
              </el-form>
            </div>
          </el-card>
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>班级信息</span>
              <el-button style="float: right; padding: 3px 0" type="text" v-if="!stuClassInfoFormDisabled"
                         @click="handleAddStuClassRelation">新增
              </el-button>
            </div>
            <div class="text item">
              <el-table v-loading="loading" :data="stuClassRelationList"
                        size="mini">
                <el-table-column label="校区" align="center" prop="params.schoolArea" width="70"/>
                <el-table-column label="学院" align="center" prop="params.college"/>
                <el-table-column label="年级" align="center" prop="params.grade" width="60"/>
                <el-table-column label="专业班级" align="center" prop="params.proClass" :show-overflow-tooltip="true"/>
                <el-table-column label="变动日期" align="center" prop="changeDateTime" width="110">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.changeDateTime, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="备注" align="center" prop="remark"/>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right"
                                 width="90">
                  <template slot-scope="scope">
                    <el-button
                      v-if="!stuClassInfoFormDisabled"
                      size="mini"
                      type="text"
                      icon="el-icon-edit"
                      @click="handleStuClassRelationUpdate(scope.row)"
                      v-hasPermi="['stuManage:stuClassRelation:edit']"
                    >
                    </el-button>
                    <el-button
                      v-if="!stuClassInfoFormDisabled"
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click="handleStuClassRelationDelete(scope.row)"
                      v-hasPermi="['stuManage:stuClassRelation:remove']"
                    >
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
              <div style="margin-top: 5px" v-if="stuClassCasAvailable">
                <el-form :model="stuClassRelation" :inline="true" :disabled="stuClassInfoFormDisabled"
                         class="demo-form-inline">
                  <el-row>
                    <el-col :span="6">
                      <el-form-item label="">
                        <el-cascader
                          v-model="form.areaCollegeGradeProClass"
                          :options="stuClassCasList"
                          :props="casProps"
                          placeholder="班级"
                        ></el-cascader>
                      </el-form-item>
                    </el-col>
                    <el-col :span="7">
                      <el-form-item label="">
                        <el-date-picker
                          v-model="stuClassRelation.changeDateTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="变更日期"
                        >
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="">
                        <el-input v-model="stuClassRelation.remark" placeholder="备注"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item>
                        <el-button type="primary" size="mini" @click="addStuClassRelation">确认</el-button>
                        <el-button type="warning" size="mini" @click="cancelAddStuClassRelation">取消</el-button>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
            </div>
          </el-card>
          <el-card style="margin-top: 5px" class="box-card">
            <div slot="header" class="clearfix">
              <span>宿舍信息</span>
              <el-button @click="stuDorCasAvailable=true" style="float: right; padding: 3px 0" type="text">新增
              </el-button>
            </div>
            <div class="text item">
              <el-table v-loading="loading" :data="stuDorRelationList"
                        size="mini">
                <el-table-column label="校区" align="center" prop="params.schoolArea" width="70"/>
                <el-table-column label="楼栋" align="center" prop="params.buildingNo" width="70"/>
                <el-table-column label="房间" align="center" prop="params.roomNo" width="70"/>
                <el-table-column label="床位" align="center" prop="params.bedNo" width="70"/>
                <el-table-column label="变动日期" align="center" prop="remark" width="110">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.changeDateTime, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="备注" align="center" prop="remark"/>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right"
                                 width="90">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-edit"
                      @click="handleStuDorRelationUpdate(scope.row)"
                      v-hasPermi="['stuManage:stuDorRelation:edit']"
                    >
                    </el-button>
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click="handleDeleteStuDorRelation(scope.row)"
                      v-hasPermi="['stuManage:stuDorRelation:remove']"
                    >
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
              <div style="margin-top: 5px" v-if="stuDorCasAvailable">
                <el-form :inline="true" :model="stuDorRelation" :disabled="stuDorInfoFormDisabled"
                         class="demo-form-inline">
                  <el-row>
                    <el-col :span="6">
                      <el-form-item label="">
                        <el-cascader
                          v-model="form.areaBuildingFloorRoomBed"
                          :options="stuDorCasList"
                          placeholder="宿舍"
                          :props="{label:'label',value:'id',checkStrictly: true}"
                          @change="handleStuDorChange"></el-cascader>
                      </el-form-item>
                    </el-col>
                    <el-col :span="5">
                      <el-form-item label="">
                        <el-date-picker
                          style="width: 160px"
                          v-model="stuDorRelation.changeDateTime"
                          type="date"
                          placeholder="变更日期"
                          value-format="yyyy-MM-dd"
                        >
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="9">
                      <el-form-item label="">
                        <el-input style="width: 300px" v-model="stuDorRelation.remark" placeholder="备注"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item>
                        <el-button type="primary" size="mini" @click="addStuDorRelation">确认</el-button>
                        <el-button type="warning" size="mini" @click="cancelAddStuDorRelation">取消</el-button>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="14">
          <el-card style="margin-top: 5px" class="box-card">
            <div slot="header" class="clearfix">
              <span>请假信息</span>
              <el-button @click="stuLeaveAvailable=true" style="float: right; padding: 3px 0" type="text">新增
              </el-button>
            </div>
            <div class="text item">
              <el-table :data="leaveList">
                <el-table-column label="预计离校时间" align="center" prop="expectLeaveTime" width="110">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.expectLeaveTime, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="预计返校时间" align="center" prop="expectReturnTime" width="110">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.expectReturnTime, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="实际返校时间" align="center" prop="realReturnTime" width="110">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.realReturnTime, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="原因" align="center" prop="reason"/>
                <el-table-column label="目的地" align="center" prop="destination"/>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="90">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-edit"
                      @click="handleStuLeaveUpdate(scope.row)"
                    >
                    </el-button>
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click="handleStuLeaveDelete(scope.row)"
                    >
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
              <div style="margin-top: 5px" v-if="stuLeaveAvailable">
                <el-form :model="stuLeave" size="mini"
                         class="demo-form-inline">
                  <el-row :gutter="8">
                    <el-col :span="4">
                      <el-form-item label="" prop="expectLeaveTime">
                        <el-date-picker clearable
                                        style="width: 135px"
                                        v-model="stuLeave.expectLeaveTime"
                                        type="date"
                                        value-format="yyyy-MM-dd"
                                        :picker-options="pickerBeginOption"
                                        placeholder="预计离校时间">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item label="" prop="expectReturnTime">
                        <el-date-picker clearable
                                        style="width: 135px"
                                        v-model="stuLeave.expectReturnTime"
                                        type="date"
                                        :picker-options="pickerBeginOption"
                                        value-format="yyyy-MM-dd"
                                        placeholder="预计返校时间"
                        >
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item label="" prop="realReturnTime">
                        <el-date-picker clearable
                                        style="width: 135px"
                                        v-model="stuLeave.realReturnTime"
                                        type="date"
                                        :picker-options="pickerBeginOption"
                                        value-format="yyyy-MM-dd"
                                        placeholder="实际返校时间"
                        >
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item label="" prop="reason">
                        <el-input v-model="stuLeave.reason" placeholder="原因"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item label="" prop="destination">
                        <el-input v-model="stuLeave.destination" placeholder="目的地"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item>
                        <el-button type="primary" @click="addOrUpdateStuLeave">确认</el-button>
                        <el-button type="warning" @click="cancelAddOrUpdateStuLeave">取消</el-button>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
            </div>
          </el-card>
          <el-card style="margin-top: 5px" class="box-card">
            <div slot="header" class="clearfix">
              <span>离校信息</span>
              <el-button @click="leaveSchoolShow=true" style="float: right; padding: 3px 0" type="text">新增</el-button>
            </div>
            <div class="text item">
              <el-table :data="leaveSchoolList">
                <el-table-column label="计划离校时间" align="center" prop="expectTime" width="110"/>
                <el-table-column label="延迟离校" align="center" prop="isDelay" width="110">
                  <template slot-scope="scope">
                    <span v-if="scope.row.isDelay">是</span>
                    <span v-else>否</span>
                  </template>
                </el-table-column>
                <el-table-column label="原因" align="center" prop="delayReason" width="110"/>
                <el-table-column label="目的地" align="center" prop="dest"/>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="90">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-edit"
                      @click="showLeaveSchoolForm(scope.row)"
                    >
                    </el-button>
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click="delLeaveSchool(scope.row)"
                    >
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>

              <div style="margin-top: 5px" v-if="leaveSchoolShow">
                <el-form :model="leaveSchool" size="mini" class="demo-form-inline">
                  <el-row :gutter="8.5">
                    <el-col :span="4">
                      <el-form-item label="">
                        <el-date-picker clearable
                                        style="width: 135px"
                                        v-model="leaveSchool.expectTime"
                                        type="date"
                                        value-format="yyyy-MM-dd"
                                        :picker-options="pickerBeginOption"
                                        placeholder="计划离校时间">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item label="">
                        <el-select v-model="leaveSchool.isDelay" placeholder="是否延迟离校">
                          <el-option
                            key="1"
                            label="是"
                            :value="1">
                          </el-option>
                          <el-option
                            key="0"
                            label="否"
                            :value="0">
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4" v-if="leaveSchool.isDelay">
                      <el-form-item label="">
                        <el-input v-model="leaveSchool.delayReason" placeholder="延迟离校原因"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item label="">
                        <el-cascader
                          v-model="leaveSchool.dest"
                          :options="areas"
                          :props="{label: 'areaName',value: 'areaName',checkStrictly: true}"
                          placeholder="省市区"
                        ></el-cascader>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item>
                        <el-button type="primary" @click="addUpdateLeaveSchool">确认</el-button>
                        <el-button type="warning" @click="cancelLeaveSchool">取消</el-button>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
            </div>
          </el-card>
          <el-card style="margin-top: 5px" class="box-card">
            <div slot="header" class="clearfix">
              <span>留校信息</span>
              <el-button @click="stayAtSchoolShow=true" style="float: right; padding: 3px 0" type="text">新增</el-button>
            </div>
            <div class="text item">
              <el-table :data="stayAtSchoolList">
                <el-table-column label="原因" align="center" prop="stayReason"/>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-edit"
                      @click="showStayAtSchoolForm(scope.row)"
                    >
                    </el-button>
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click="delStayAtSchool(scope.row)"
                    >
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>

              <div style="margin-top: 5px" v-if="stayAtSchoolShow">
                <el-form :model="stayAtSchool" size="mini" class="demo-form-inline">
                  <el-row :gutter="8.5">
                    <el-col :span="20">
                      <el-form-item label="">
                        <el-input v-model="stayAtSchool.stayReason" placeholder="留校原因"></el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="4">
                      <el-form-item>
                        <el-button type="primary" @click="addUpdateStayAtSchool">确认</el-button>
                        <el-button type="warning" @click="cancelStayAtSchool">取消</el-button>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 学生导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport"/>
            是否更新已经存在的学生数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
                   @click="importTemplate">下载模板
          </el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!--离校数据导入对话框-->
    <el-dialog :title="leaveUpload.title" :visible.sync="leaveUpload.open" width="400px" append-to-body>
      <el-upload
        ref="leaveUpload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="leaveUpload.headers"
        :action="leaveUpload.url + '?updateSupport=' + leaveUpload.updateSupport"
        :disabled="leaveUpload.isUploading"
        :on-progress="leaveUploadProgress"
        :on-success="leaveUploadFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="leaveUpload.updateSupport"/>
            是否更新已经存在的学生数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
                   @click="importLeaveTemplate">下载模板
          </el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitImportLeave">确 定</el-button>
        <el-button @click="leaveUpload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {listStu, getStu, delStu, addStu, updateStu} from "@/api/stu/stu";
  import {listTree} from "@/api/stu/area";
  import {findChildrenStuClassCasById, findChildrenStuClassCasByIds,findStuClassChildrenNoCas} from "@/api/stu/class";
  import {getInfo} from "@/api/login";
  import {getToken} from "@/utils/auth";
  import {
    findChildrenDorCasById,
    findChildrenDorCasByIds,
    findAreaBuildingFloorRoom,
    findChildrenNoCas
  } from "@/api/stu/dor";
  import {getUserRoleByUserId} from "@/api/stu/userRole";
  import {
    listStuClassRelation,
    getStuClassRelation,
    updateStuLatestClassRelation,
    delStuClassRelation,
    addStuClassRelation,
    updateStuClassRelation
  } from "@/api/stu/stuClassRelation";
  import {
    listStuDorRelation,
    getStuDorRelation,
    updateStuLatestDorRelation,
    delStuDorRelation,
    addStuDorRelation,
    updateStuDorRelation
  } from "@/api/stu/stuDorRelation";
  import {listLeave, getLeave, delLeave, addLeave, updateLeave} from "@/api/stu/leave";
  import {listLeaveSchool, delLeaveSchool, addLeaveSchool, updateLeaveSchool} from "@/api/stu/leaveSchool";
  import {listStayAtSchool, delStayAtSchool, addStayAtSchool, updateStayAtSchool} from "@/api/stu/stayAtSchool";


  export default {
    name: "Stu",
    dicts: ['stu_status', 'stu_type'],
    data() {
      return {
        pickerBeginOption: {
          disabledDate: (time) => {
            return time.getTime() < Date.now() - 1 * 24 * 60 * 60 * 1000
          }
        },
        // 遮罩层
        loading: true,
        // 学生宿舍关联表格遮罩层
        stuDorRelationLoading: true,
        // 学生班级关联表格遮罩层
        stuClassRelationLoading: true,
        // 选中数组
        ids: [],
        names: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 学生基本信息表格数据
        stuList: [],
        // 学生班级关联表格数据
        stuClassRelationList: [],
        // 学生寝室关联表格数据
        stuDorRelationList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: null,
          schoolAreaIds: [1, 2],
          collegeId: null,
          collegeIds: [],
          gradeId: null,
          proClassId: null,
          proClassIds: [],
          sex: null,
          type: null,
          stuNo: null,
          idNum: null,
          schoolArea: null,
          buildingId: null,
          buildingIds: [],
          roomId: null,
          bedId: null,
          phone: null,
          status: null,
          addrNow: null,
          floorId: null,
          floorIds: [],
          isMultiRoles: false,
          userRoles: [],
          collegeGradeProClass: [],
          gradeProClass: [],
          areaBuildingFloorRoom: [],
          floorRoomBedId: [],
          roomBedId: [],
          areaCollegeGradeProClass:[]
        },
        queryStuClassRelationParams: {
          pageNum: 1,
          pageSize: 10,
          stuId: null,
          schoolArea: null,
          collegeId: null,
          gradeId: null,
          proClassId: null,
          changeDateTime: null,
        },
        queryStuDorRelationParams: {
          pageNum: 1,
          pageSize: 10,
          stuId: null,
          schoolArea: null,
          buildingId: null,
          floorId: null,
          roomId: null,
          bedId: null,
          changeDateTime: null,
        },
        // 表单参数
        form: {
          areaCollegeGradeProClass: [],
          isPartyMember: null,
          isMember: null,
          isAdminDor: null,
          status: null,
          type: null,
          areaBuildingFloorRoomBed: []
        },
        // 表单校验
        rules: {},
        stuClassCasList: [],
        stuDorCasList: [],
        collegeGradeProClassList: [],
        gradeProClassList: [],
        floorRoomBedNoList: [],
        roomBedNoList: [],
        casProps: {
          label: 'label',
          value: 'id',
          checkStrictly: true
        },
        userRoles: [],
        userId: null,
        stuDorCasAvailable: false,
        stuClassCasAvailable: false,
        stuClassRelation: {},
        stuClassRelationId: 1,
        stuDorRelationId: 1,
        stuLeaveId: 1,
        stuDorRelation: {},
        stuBaseInfoFormDisabled: false,
        stuClassInfoFormDisabled: false,
        stuDorInfoFormDisabled: false,
        //是否为全校管理员
        isSchoolLevel: false,
        areaBuildingFloorRoomList: [],
        stuLeaveAvailable: false,
        leaveList: [],
        queryStuLeaveParams: {},
        stuLeave: {},
        // 学生导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: {Authorization: "Bearer " + getToken()},
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/stuManage/stu/importData"
        },
        leaveUpload: {
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: {Authorization: "Bearer " + getToken()},
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/stuManage/stu/importLeaveData"
        },
        stayAtSchool: {},
        leaveSchool: {},
        leaveSchoolId: 1,
        stayAtSchoolId: 1,
        leaveSchoolList: [],
        stayAtSchoolList: [],
        stayAtSchoolShow: false,
        leaveSchoolShow: false,
        areas: [],
        lazyLoadProps: {
          label: 'label',
          value: 'id',
          lazy: true,
          checkStrictly: true,
          async lazyLoad(node, resolve) {
            // console.log('node:',node)
            let {value,root} = node
            if (!root){
              let {data: res} = await findChildrenNoCas(value)
              resolve(res.data)
            }
          }
        },
        stuClassLazyLoadProps:{
          label: 'label',
          value: 'id',
          lazy: true,
          checkStrictly: true,
          async lazyLoad(node, resolve) {
            // console.log('node:',node)
            let {value,root} = node
            if (!root){
              let {data: res} = await findStuClassChildrenNoCas(value)
              resolve(res.data)
            }
          }
        }
      };
    },
    created() {
      // this.getUserInfo()
      // this.getStuClassCas()
      // this.getStuDorCas()
      // this.getAreaBuildingFloorRoom()
      // this.getAreaTree()
      this.getList()
      this.getChildrenDorIdLabel('0')
      this.getChildrenStuClassIdLabel('0')
    },
    methods: {
      async getChildrenDorIdLabel(parentId) {
        let {data: res} = await findChildrenNoCas(parentId)
        this.areaBuildingFloorRoomList = res.data
        // console.log('getSchoolArea:', res)
      },
      async getChildrenStuClassIdLabel(parentId) {
        let {data: res} = await findStuClassChildrenNoCas(parentId)
        this.stuClassCasList = res.data
        // console.log('getSchoolArea:', res)
      },
      // 学生班级关联表格数据
      getStuClassRelationList() {
        this.stuClassRelationLoading = true;
        this.queryStuClassRelationParams.stuId = this.form.id
        listStuClassRelation(this.queryStuClassRelationParams).then(response => {
          this.stuClassRelationList = response.rows;
          this.stuClassRelationLoading = false;
        });
      },
      getStuLeaveList() {
        this.stuClassRelationLoading = true;
        this.queryStuLeaveParams.stuId = this.form.id
        listLeave(this.queryStuLeaveParams).then(response => {
          this.leaveList = response.rows;
        });
      },
      // 学生宿舍关联表格数据
      getStuDorRelationList() {
        this.stuDorRelationLoading = true;
        this.queryStuDorRelationParams.stuId = this.form.id
        listStuDorRelation(this.queryStuDorRelationParams).then(response => {
          this.stuDorRelationList = response.rows;
          this.stuDorRelationLoading = false;
        });
      },

      handleDeleteStuDorRelation(row) {
        let stuId = this.form.id
        if (stuId) {
          this.$modal.confirm('确认删除吗？').then(function () {
            return delStuDorRelation(row.id);
          }).then(() => {
            this.$modal.msgSuccess("删除成功");
            this.getStuDorRelationList();
          });
        } else {
          this.$modal.confirm('确认删除吗？').then(function () {
          }).then(() => {
            this.stuDorRelationList = this.stuDorRelationList.filter(item => item.id !== row.id)
          });
        }
      },

      handleStuDorChange() {

      },
      handleStuLeaveUpdate(row) {
        if (row.stuId) {
          getLeave(row.id).then(res => {
            // this.form.areaBuildingFloorRoomBed = res.data.areaBuildingFloorRoomBed
            this.stuLeave = res.data
          })
        } else {
          this.stuLeave = row
          // this.form.areaBuildingFloorRoomBed = row.areaBuildingFloorRoomBed
        }
        this.stuLeaveAvailable = true
      },
      handleStuLeaveDelete(row) {
        let stuId = this.form.id
        if (stuId) {
          this.$modal.confirm('确认删除？').then(function () {
            return delLeave(row.id);
          }).then(() => {
            this.getStuLeaveList();
            this.$modal.msgSuccess("删除成功");
          }).catch(() => {
          });
        } else {
          this.$modal.confirm('确认删除？').then(function () {
          }).then(() => {
            this.leaveList = this.leaveList.filter(item => item.id !== row.id)
          }).catch(() => {
          });
        }
      },

      getAreaBuildingFloorRoom() {
        findAreaBuildingFloorRoom().then(res => {
          this.areaBuildingFloorRoomList = res.data
        })
      },
      addOrUpdateStuLeave() {
        let stuId = this.form.id
        if (stuId) {
          if (this.stuLeave.id) {
            updateLeave(this.stuLeave).then(res => {
              if (res.code === 200) {
                this.$message.success("修改学生请假记录成功！")
                this.getStuLeaveList()
                this.cancelAddOrUpdateStuLeave()
              }
            })
          } else {
            this.stuLeave.stuId = stuId
            addLeave(this.stuLeave).then(res => {
              if (res.code === 200) {
                this.$message.success("添加学生请假记录成功！")
                this.getStuLeaveList()
                this.cancelAddOrUpdateStuLeave()
              }
            })
          }
        } else {
          if (this.stuLeave.id) {
            this.leaveList.forEach(item => {
              if (item.id === this.stuLeave.id) {
                item = this.stuLeave
              }
            })
          } else {
            this.stuLeave.id = this.stuLeaveId++
            this.leaveList.push(this.stuLeave)
          }
          this.cancelAddOrUpdateStuLeave()
        }
      },
      cancelAddOrUpdateStuLeave() {
        this.stuLeave = {}
        this.stuLeaveAvailable = false
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", {dangerouslyUseHTMLString: true});
        this.getList();
      },
      submitFileForm() {
        this.$refs.upload.submit();
      },
      /** 下载模板操作 */
      importTemplate() {
        this.download('/stuManage/stu/importTemplate', {}, `stu_template_${new Date().getTime()}.xlsx`)
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = "学生导入";
        this.upload.open = true;
      },

      // 学生班级关联信息修改 信息回显
      handleStuClassRelationUpdate(row) {
        if (row.stuId) {
          getStuClassRelation(row.id).then(res => {
            this.form.areaCollegeGradeProClass = res.data.areaCollegeGradeProClass
            this.stuClassRelation = res.data
          })
        } else {
          this.stuClassRelation = row
          this.form.areaCollegeGradeProClass = row.areaCollegeGradeProClass
        }
        this.stuClassCasAvailable = true
      },
      // 学生宿舍关联信息修改 信息回显
      handleStuDorRelationUpdate(row) {
        if (row.stuId) {
          getStuDorRelation(row.id).then(res => {
            this.form.areaBuildingFloorRoomBed = res.data.areaBuildingFloorRoomBed
            this.stuDorRelation = res.data
          })
        } else {
          this.stuDorRelation = row
          this.form.areaBuildingFloorRoomBed = row.areaBuildingFloorRoomBed
        }
        this.stuDorCasAvailable = true
      },

      // 显示 新增学生班级关联信息 表单
      handleAddStuClassRelation() {
        this.form.areaCollegeGradeProClass = []
        this.stuClassCasAvailable = true
      },
      // 添加或修改学生班级关联信息
      addStuClassRelation() {
        this.stuClassRelation.areaCollegeGradeProClass = this.form.areaCollegeGradeProClass
        this.stuClassRelation.stuId = this.form.id
        // 修改学生班级关联信息
        if (this.stuClassRelation.stuId) {
          if (this.stuClassRelation.id) {
            updateStuClassRelation(this.stuClassRelation).then(res => {
              this.getStuClassRelationList()
              updateStuLatestClassRelation(this.form.id)
            })
          } else {
            addStuClassRelation(this.stuClassRelation).then(res => {
              this.getStuClassRelationList()
              updateStuLatestClassRelation(this.form.id)
            })
          }
        } else {
          if (this.stuClassRelation.id) {
            this.stuClassRelationList.forEach(item => {
              if (item.id === this.stuClassRelation.id) {
                item = this.stuClassRelation
              }
            })
          } else {
            this.stuClassRelation.id = this.stuClassRelationId++
            this.stuClassRelationList.push(this.stuClassRelation)
          }
        }
        this.cancelAddStuClassRelation()
      },
      // 添加或修改学生宿舍关联信息
      addStuDorRelation() {
        this.stuDorRelation.areaBuildingFloorRoomBed = this.form.areaBuildingFloorRoomBed
        this.stuDorRelation.stuId = this.form.id
        if (this.stuDorRelation.stuId) {
          // 修改
          if (this.stuDorRelation.id) {
            updateStuDorRelation(this.stuDorRelation).then(res => {
              this.getStuDorRelationList()
              updateStuLatestDorRelation(this.form.id)
            })
          } else {
            addStuDorRelation(this.stuDorRelation).then(res => {
              this.getStuDorRelationList()
              updateStuLatestDorRelation(this.form.id)
            })
          }
        } else {
          if (this.stuDorRelation.id) {
            this.stuDorRelationList.forEach(item => {
              if (item.id === this.stuDorRelation.id) {
                item = this.stuDorRelation
              }
            })
          } else {
            this.stuDorRelation.id = this.stuDorRelationId++
            this.stuDorRelationList.push(this.stuDorRelation)
          }
        }
        this.cancelAddStuDorRelation()
      },
      // 隐藏添加学生宿舍的行内表单
      cancelAddStuDorRelation() {
        this.form.areaBuildingFloorRoomBed = []
        this.stuDorRelation = {}
        this.stuDorCasAvailable = false
      },
      // 隐藏添加学生班级的行内表单
      cancelAddStuClassRelation() {
        this.form.areaCollegeGradeProClass = []
        this.stuClassRelation = {}
        this.stuClassCasAvailable = false
      },

      handleStuClassRelationDelete(row) {
        let stuId = this.form.id
        if (stuId) {
          this.$modal.confirm('确认删除？').then(function () {
            return delStuClassRelation(row.id);
          }).then(() => {
            this.getStuClassRelationList();
            this.$modal.msgSuccess("删除成功");
          }).catch(() => {
          });
        } else {
          this.$modal.confirm('确认删除？').then(function () {
          }).then(() => {
            this.leaveList = this.leaveList.filter(item => item.id !== row.id)
          }).catch(() => {
          });
        }
      },

      addUpdateStayAtSchool() {
        let stuId = this.form.id
        this.stayAtSchool.stuId = stuId
        if (stuId) {
          if (this.stayAtSchool.id) {
            updateStayAtSchool(this.stayAtSchool).then(res => {
              this.getStayAtSchoolList()
              this.cancelStayAtSchool()
              this.$message.success('更新学生在校信息成功')
            })
          } else {
            addStayAtSchool(this.stayAtSchool).then(res => {
              this.getStayAtSchoolList()
              this.cancelStayAtSchool()
              this.$message.success('添加学生在校信息成功')
            })
          }
        } else {
          if (this.stayAtSchool.id) {
            this.stayAtSchoolList.forEach(item => {
              if (item.id === this.stayAtSchool.id) {
                item = this.stayAtSchool
              }
            })
          } else {
            this.stayAtSchool.id = this.stayAtSchoolId++
            this.stayAtSchoolList.push(this.stayAtSchool)
          }
          this.cancelStayAtSchool()
        }
      },
      cancelStayAtSchool() {
        this.stayAtSchoolShow = false
        this.stayAtSchool = {}
      },
      getStayAtSchoolList() {
        listStayAtSchool({stuId: this.form.id}).then(res => {
          this.stayAtSchoolList = res
        })
      },
      showStayAtSchoolForm(row) {
        // let stuId=this.form.id
        this.stayAtSchool = row
        this.stayAtSchoolShow = true
      },

      delStayAtSchool(row) {
        let stuId = this.form.id
        if (stuId) {
          this.$modal.confirm('确认删除？').then(function () {
            return delStayAtSchool(row.id);
          }).then(() => {
            this.$modal.msgSuccess("删除成功");
            this.getStayAtSchoolList();
          });
        } else {
          this.$modal.confirm('确认删除吗？').then(function () {
          }).then(() => {
            this.stayAtSchoolList = this.stayAtSchoolList.filter(item => item.id !== row.id)
          });
        }
      },


      getLeaveSchoolList() {
        listLeaveSchool({stuId: this.form.id}).then(res => {
          this.leaveSchoolList = res
        })
      },
      addUpdateLeaveSchool() {
        let stuId = this.form.id
        this.leaveSchool.stuId = stuId
        if (stuId) {
          this.leaveSchool.dest = String(this.leaveSchool.dest)
          if (this.leaveSchool.id) {
            updateLeaveSchool(this.leaveSchool).then(res => {
              this.$message.success('修改学生离校信息成功！')
              this.getLeaveSchoolList()
              this.cancelLeaveSchool()
            })
          } else {
            addLeaveSchool(this.leaveSchool).then(res => {
              this.$message.success('添加学生离校信息成功！')
              this.getLeaveSchoolList()
              this.cancelLeaveSchool()
            })
          }
        } else {
          if (this.leaveSchool.id) {
            this.leaveSchoolList.forEach(item => {
              if (item.id === this.leaveSchool.id) {
                item = this.leaveSchool
                item.dest = String(item.dest)
              }
            })
          } else {
            this.leaveSchool.id = this.leaveSchoolId++
            this.leaveSchool.dest = String(this.leaveSchool.dest)
            this.leaveSchoolList.push(this.leaveSchool)
          }
          this.cancelLeaveSchool()
        }

      },
      delLeaveSchool(row) {
        let stuId = this.form.id
        if (stuId) {
          this.$modal.confirm('确认删除？').then(function () {
            return delLeaveSchool(row.id);
          }).then(() => {
            this.$modal.msgSuccess("删除成功");
            this.getLeaveSchoolList();
          });
        } else {
          this.$modal.confirm('确认删除吗？').then(function () {
          }).then(() => {
            this.leaveSchoolList = this.leaveSchoolList.filter(item => item.id !== row.id)
          });
        }
      },
      showLeaveSchoolForm(row) {
        let stuId = this.form.id
        this.leaveSchool = row
        this.leaveSchool.dest = this.leaveSchool.dest.split(',')
        this.leaveSchoolShow = true
      },
      cancelLeaveSchool() {
        this.leaveSchoolShow = false
        this.leaveSchool = {}
      },

      getStuClassCas() {
        findChildrenStuClassCasById({parentId: 0}).then(res => {
          this.stuClassCasList = res.data
        })
      },

      getStuDorCas() {
        findChildrenDorCasById({parentId: 0}).then(res => {
          this.stuDorCasList = res.data
        })
      },
      async getUserRoles() {
        let {data: res} = await getUserRoleByUserId(this.userId)
        console.log('getUserRoles:', res)
        this.userRoles = res
        if (this.userRoles.length > 1) {
          this.queryParams.isMultiRoles = true
        }
        let isOldAdmin = false
        let isNewAdmin = false
        this.userRoles.forEach(item => {
          this.queryParams.userRoles.push(item.roleType + '-' + item.roleId)
          if (item.roleType === 1) this.queryParams.schoolAreaIds.push(item.roleId)
          if (item.roleType === 2) this.queryParams.collegeIds.push(item.roleId)
          if (item.roleType === 3) this.queryParams.proClassIds.push(item.roleId)
          if (item.roleType === 4) this.queryParams.buildingIds.push(item.roleId)
          if (item.roleType === 5) this.queryParams.floorIds.push(item.roleId)
          if (item.roleId === 1) isNewAdmin = true
          if (item.roleId === 2) isOldAdmin = true
        })
        if (isOldAdmin && isNewAdmin) {
          this.isSchoolLevel = true
        }

        this.getList()
        this.initProps()
      },
      getAreaTree() {
        listTree().then(res => {
          this.areas = res
        })
      },

      initProps() {
        if (this.queryParams.collegeIds.length > 0 && this.queryParams.proClassIds.length > 0) {
          this.queryParams.proClassIds = []
        }
        if (this.queryParams.collegeIds.length > 0 && this.queryParams.buildingIds.length > 0) {
          this.queryParams.buildingIds = []
        }
        if (this.queryParams.schoolAreaIds.length > 0 && this.queryParams.collegeIds.length > 0) {
          this.queryParams.collegeIds = []
        }
        if (this.queryParams.buildingIds.length > 0 && this.queryParams.floorIds.length > 0) {
          this.queryParams.floorIds = []
        }
        //  校级领导通过学院进行学生的条件查询
        if (this.queryParams.schoolAreaIds.length > 0) {
          this.getCollegeGradeProClassList(this.queryParams.schoolAreaIds)
        }
        if (this.queryParams.collegeIds.length > 0) {
          this.getGradeProClassList(this.queryParams.collegeIds)
        }
        if (this.queryParams.buildingIds.length > 0) {
          this.getFloorRoomList(this.queryParams.buildingIds)
          this.stuBaseInfoFormDisabled = true
          this.stuClassInfoFormDisabled = true
        }
        if (this.queryParams.floorIds.length > 0) {
          this.getRoomBedList(this.queryParams.floorIds)
          this.stuBaseInfoFormDisabled = true
          this.stuClassInfoFormDisabled = true
        }
      },
      async getUserInfo() {
        let {user} = await getInfo()
        this.userId = user.userId
        this.getUserRoles()
      },
      getGradeProClassList(collegeIds) {
        findChildrenStuClassCasByIds(collegeIds).then(res => {
          this.gradeProClassList = res.data
        })
      },
      getCollegeGradeProClassList(schoolAreaIds) {
        findChildrenStuClassCasByIds(schoolAreaIds).then(res => {
          this.collegeGradeProClassList = res.data
        })
      },
      getFloorRoomList(buildingIds) {
        findChildrenDorCasByIds(buildingIds).then(res => {
          this.floorRoomBedNoList = res.data
        })
      },
      getRoomBedList(floorIds) {
        findChildrenDorCasByIds(floorIds).then(res => {
          this.roomBedNoList = res.data
        })
      },
      /** 查询学生基本信息列表 */
      async getList() {
        this.loading = true;
        this.buildQueryParams()
        this.queryParams.schoolAreaIds = this.queryParams.schoolAreaIds.toString()
        let {data:res} = await listStu(this.queryParams)
        this.stuList = res.rows;
        this.total = res.total;
        this.loading = false;
      },
      buildQueryParams() {
        if(this.queryParams.userRoles.length>0){
          this.queryParams.userRoles = this.queryParams.userRoles + ''
        }
        if(this.queryParams.schoolAreaIds.length>0){
          this.queryParams.schoolAreaIds = this.queryParams.schoolAreaIds + ''
        }
        if(this.queryParams.collegeIds.length>0){
          this.queryParams.collegeIds = this.queryParams.collegeIds + ''
        }
        if(this.queryParams.proClassIds.length>0){
          this.queryParams.proClassIds = this.queryParams.proClassIds + ''
        }
        if(this.queryParams.buildingIds.length>0){
          this.queryParams.buildingIds = this.queryParams.buildingIds + ''
        }
        if(this.queryParams.floorIds.length>0){
          this.queryParams.floorIds = this.queryParams.floorIds + ''
        }
        if(this.queryParams.areaCollegeGradeProClass.length>0){
          this.queryParams.areaCollegeGradeProClass = this.queryParams.areaCollegeGradeProClass + ''
        }
        if(this.queryParams.collegeGradeProClass.length>0){
          this.queryParams.collegeGradeProClass = this.queryParams.collegeGradeProClass + ''
        }
        if(this.queryParams.gradeProClass.length>0){
          this.queryParams.gradeProClass = this.queryParams.gradeProClass + ''
        }
        if(this.queryParams.areaBuildingFloorRoom.length>0){
          this.queryParams.areaBuildingFloorRoom = this.queryParams.areaBuildingFloorRoom + ''
        }
        if(this.queryParams.floorRoomBedId.length>0){
          this.queryParams.floorRoomBedId = this.queryParams.floorRoomBedId + ''
        }
        if(this.queryParams.roomBedId.length>0){
          this.queryParams.roomBedId = this.queryParams.roomBedId + ''
        }
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {};
        this.stuClassRelationList = []
        this.stuDorRelationList = []
        this.leaveList = []
        this.leaveSchoolList = []
        this.stayAtSchoolList = []
        this.resetForm("form");
        this.cancelAddStuDorRelation()
        this.cancelAddStuClassRelation()
        this.cancelAddOrUpdateStuLeave()
        this.cancelStayAtSchool()
        this.cancelLeaveSchool()
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.$tab.refreshPage()
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.names = selection.map(item => item.name)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加学生信息";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getStu(id).then(response => {
          this.form = response.data;
          this.getStuClassRelationList()
          this.getStuDorRelationList()
          this.getStuLeaveList()
          this.getLeaveSchoolList()
          this.getStayAtSchoolList()
          this.form.type = this.form.type + ''
          this.form.status = this.form.status + ''
          this.open = true;
          this.title = "修改学生信息";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.form.stuDorRelationList = this.stuDorRelationList
        this.form.stuClassRelationList = this.stuClassRelationList
        this.form.leaveSchoolList = this.leaveSchoolList
        this.form.stayAtSchoolList = this.stayAtSchoolList
        this.form.stuLeaveList = this.leaveList
        if (this.leaveSchoolList.length > 0) {
          this.form.status = '12'
        }
        if (this.stayAtSchoolList.length > 0) {
          this.form.status = '1'
        }
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              this.form.schoolArea = null

              this.form.buildingId = null
              this.form.floorId = null
              this.form.roomId = null
              this.form.bedId = null

              this.form.collegeId = null
              this.form.gradeId = null
              this.form.proClassId = null

              updateStu(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.reset()
                this.getList()
                // this.$tab.refreshPage()
              });
            } else {
              addStu(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.reset()
                this.getList()
                // this.$tab.refreshPage()
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        const names = row.name || this.names;
        this.$modal.confirm('确认删除学生【' + names + '】信息？').then(function () {
          return delStu(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('stuManage/stu/export', {
          ...this.queryParams
        }, `stu_${new Date().getTime()}.xlsx`)
      },
      importLeaveData() {
        this.leaveUpload.title = "导入离校数据";
        this.leaveUpload.open = true;
      },
      leaveUploadProgress() {
        this.leaveUpload.isUploading = true;
      },
      leaveUploadFileSuccess(response) {
        this.leaveUpload.open = false;
        this.leaveUpload.isUploading = false;
        this.$refs.leaveUpload.clearFiles();
        this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", {dangerouslyUseHTMLString: true});
        // this.getList();
      },
      importLeaveTemplate() {
        this.download('/stuManage/stu/importLeaveTemplate', {}, `stu_leave_template_${new Date().getTime()}.xlsx`)
      },
      submitImportLeave() {
        this.$refs.leaveUpload.submit();
      }
    }
  };
</script>

<style>
  .el-dialog__body {
    padding: 0 20px;
  }

</style>
